package net.jsoft.pms.util;

import java.io.File;
import java.io.InputStream;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import net.sf.mpxj.MPXJException;
import net.sf.mpxj.ProjectFile;
import net.sf.mpxj.mpp.MPPReader;

public class ReadProjectMpp
{
    private static final Logger logger = LogManager.getLogger();

    public static ProjectFile readFile(String filePath)
    {

        // List<Task> tasks = null;
        ProjectFile pf = null;
        try
        {
            File file = new File(filePath);
            MPPReader mppRead = new MPPReader();
            pf = mppRead.read(file);
            // tasks = pf.getAllTasks();
        }
        catch (MPXJException e)
        {
            e.printStackTrace();
            logger.info("MPXJUtils.method [readFile]: MPXJException-" + e);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            logger.info("MPXJUtils.method [readFile]: MPXJException-" + e);
        }
        return pf;
    }

    public static ProjectFile readFile(InputStream is)
    {

        ProjectFile pf = null;
        try
        {
            MPPReader mppRead = new MPPReader();
            pf = mppRead.read(is);
        }
        catch (MPXJException e)
        {
            e.printStackTrace();
            logger.info("MPXJUtils.method [readFile]: MPXJException-" + e);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            logger.info("MPXJUtils.method [readFile]: MPXJException-" + e);
        }
        return pf;
    }

}
